#include <iostream>
#include <vector>
using namespace std;

struct list_node {
    int val;
    struct list_node* next;
};

list_node* input_list(void)
{
    int n, val;
    list_node* phead = new list_node();
    list_node* cur_pnode = phead;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> val;
        if (i == 1) {
            cur_pnode->val = val;
            cur_pnode->next = NULL;
        }
        else {
            list_node* new_pnode = new list_node();
            new_pnode->val = val;
            new_pnode->next = NULL;
            cur_pnode->next = new_pnode;
            cur_pnode = new_pnode;
        }
    }
    return phead;
}


list_node* reverse_list(list_node* head, int L, int R)
{
    if (head == nullptr)
        return nullptr;

    list_node* new_pre_head = new list_node;
    new_pre_head->next = nullptr;
    list_node* cur = head;
    list_node* new_cur = new_pre_head;

    while (cur != nullptr && cur->val != L)
    {
        list_node* temp = new list_node;
        temp->next = nullptr;
        temp->val = cur->val;
        new_cur->next = temp;
        new_cur = temp;
        cur = cur->next;
    }
    if (cur == nullptr)
	{
		delete new_pre_head;
		new_pre_head = nullptr;
		return head;
	}

    vector<int> val_vec;
    while (cur->val != R)
    {
        val_vec.push_back(cur->val);
        cur = cur->next;
    }

    while (val_vec.size() != 0)
    {
        list_node* temp = new list_node;
        temp->next = nullptr;
        temp->val = val_vec[val_vec.size() - 1];
        new_cur->next = temp;
        new_cur = temp;
        val_vec.pop_back();
    }

    while (cur != nullptr)
    {
        list_node* temp = new list_node;
        temp->next = nullptr;
        temp->val = cur->val;
        new_cur->next = temp;
        new_cur = temp;
        cur = cur->next;
    }

    list_node* ret = new_pre_head->next;
    delete new_pre_head;
    new_pre_head = nullptr;
    return ret;
}

void print_list(list_node* head)
{
    while (head != NULL) {
        printf("%d ", head->val);
        head = head->next;
    }
    puts("");
}


int main()
{
    int L, R;
    list_node* head = input_list();
    cin >> L >> R;
    list_node* new_head = reverse_list(head, L, R);
    print_list(new_head);
    return 0;
}